#!/bin/bash


SOURCE_DIR=/Users/heropc/go/src/image-gocv
TARGET_DIR=/Users/heropc/go/src/image-gocv/source/image-gocv

CON_NAME=image-gocv-build
CON_SOURCE=/source
WORK_DIR=$CON_SOURCE/image-gocv

docker rm -f $CON_NAME
docker pull ghcr.dockerproxy.com/hybridgroup/opencv:4.8.1
docker run -d --name image-gocv-build ghcr.dockerproxy.com/hybridgroup/opencv:4.8.1 sh -c "while true; do sleep 1; done"
docker exec $CON_NAME sh -c "go env -w GOPROXY=https://goproxy.cn,direct"
docker exec $CON_NAME sh -c "mkdir -p $WORK_DIR"
docker cp $SOURCE_DIR $CON_NAME:$CON_SOURCE
docker exec $CON_NAME sh -c "cd $WORK_DIR"
docker exec $CON_NAME sh -c "cd $WORK_DIR && go mod tidy"
docker exec $CON_NAME sh -c "cd $WORK_DIR && go build -o main ./cmd/main.go"
docker cp $CON_NAME:$WORK_DIR/main $TARGET_DIR/main
docker rm -f $CON_NAME
